// miniprogram/pages/login/login.js
var app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    emailtxt:"请输入账号或者手机号码",
    pwdtxt:"请输入密码",
    pwdtype:"password",
    logintext:"验证码登录",
    email:"",
    pwd:"",
    width:'100%',
    btntext:"点击获取验证码",
    hidden:'none',
    cartItems: [],
    canIUse: wx.canIUse('button.open-type.getUserInfo')
  },

  onLoad: function () {

  },

  bindGetUserInfo:function(e){
    let that = this;
    
    wx.showLoading({
      title: '加载中...',
    })
    wx.login({
      success(info) {
        if (info.code) {
            wx.getUserInfo({
              success: function (resInfo) {
                  wx.request({
                    url: app.globalData.url +'index.php?s=api/user/login',
                    header: {
                      'content-type': 'application/x-www-form-urlencoded'
                    },
                    data: {
                      code: info.code,
                      app_id: 10001,
                      user_info:resInfo.rawData
                    },
                    method: "POST",
                    success(res) {
                      wx.hideLoading();

                      if (res.data.code == 1) {
                        app.globalData.token = res.data.data.token;
                        wx.setStorageSync('token', app.globalData.token);
                        app.globalData.rawData = resInfo.rawData;
                        wx.setStorageSync('rawData', app.globalData.rawData);
                        app.globalData.uid = res.data.data.user_id;
                        wx.setStorageSync('user_id', app.globalData.uid);
                        wx.reLaunch({
                          url: '/pages/personal/index'
                        })
                      } else {
                        wx.showToast({
                          title: res.data.msg,
                          icon: 'none',
                          duration: 3000
                        })
                        setTimeout(function () {
                          wx.hideToast()
                        }, 3000)
                        return false;
                      }
                    }
                  })                
              }
            })
        } else {
          wx.hideLoading();
          wx.showToast({
            title: res.errMsg,
            icon: 'none',
            duration: 3000
          })
      
        }  
      }
    })

  },

  onShareAppMessage: function () {
    app.globalData.uid = app.globalData.uid || wx.getStorageSync('uid') || 0;
    return {
      title: '深圳智汇创想科技有限责任公司员工福利购!',
      path: '/pages/index/index?fid=' + app.globalData.uid
    }
  }

  
})